import axios from "axios";
import { useAuthStore } from '@/stores/auth.js'; // 确保这个路径是正确的
// 创建axios实例
export const request = axios.create({
    timeout: 20000,
    baseURL: '',
});

// 请求拦截器
request.interceptors.request.use(
    (config) => {
        const authStore = useAuthStore();
        const token = authStore.token; // 从 Pinia store 获取 token
        if (token) {
            config.headers.token = `${token}`;
        }
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

export default request;
